var PATH_PREFIX ="";

function setPathPrefix(path){
	PATH_PREFIX =  path;
}
$(function() {
	WASP_WIDGET.initializeSelectStyle();
	WASP_WIDGET.triggerDateStyleWithYMD("#beginDate");
	WASP_WIDGET.triggerDateStyleWithYMD("#endDate");
	// 注册清空事件
	WASP_WIDGET.registerResetClearEvent();
	WASP_WIDGET.triggerPrdInfoSelect("productId");
	// 注册清空事件
	WASP_WIDGET.triggerCustInfoSelect("custNo");
	WASP_WIDGET.triggerDictionarySelect("transferType","TRANSFER_CATEGORY");
});

var $custTransferList = $('#custTransferList');

$(function() {
	$custTransferList.jqGrid({   
		url:PATH_PREFIX + 'custTransferDetailListPage.do', 
		/*caption:'客户划款明细列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',*/  
		datatype: "json",
		colNames:["id", "资金日期","产品名称","资金类型","客户姓名","付款状态","付款金额","累计付款金额"],        
		colModel:[  { name: 'transferId', index: 'transferId', key: true, hidden:true },       
		            { name: 'capitalDate', index: 'capitalDate', width: 40, resizable: true, sortable: false },
		            { name: 'productName', index: 'productName', width: 30, resizable: true, sortable: false },
		            { name: 'capitalType', index: 'capitalType', width: 40, resizable: true, sortable: false },
		            { name: 'custName', index: 'custName', width: 40, resizable: true, sortable: false },
		            { name: 'paymentStatus', index: 'paymentStatus', width: 40, resizable: true, sortable: false },
		            { name: 'paymentAmount', index: 'paymentAmount', width: 40, resizable: true, sortable: false },
		            { name: 'totalPayamount', index: 'totalPayamount', width: 40, resizable: true, sortable: false }
				  ],
		rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        postData: {},
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: 'auto',
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		pager: "#custTransferListPage",						
		viewrecords: true,
		hidegrid: false, 
		gridComplete: function(){
			var ids = $custTransferList.jqGrid('getDataIDs');
			for(var i = 0;i < ids.length;i++){
				var rowId = ids[i];
				$custTransferList.jqGrid('setRowData', ids[i]);
			}	
		}
	});
	$custTransferList.navGrid('#custTransferListPage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$custTransferList.jqGrid('setFrozenColumns');
	jqGridResize($custTransferList);
});

//绑定回车事件,查询
$("body").keypress(function(event){
	var key = event.which;
	if(key == "13"){
		queryByCondtion(true);
	}
});


function queryByCondtion1(flag) {
	var beginDate = $.trim($("#beginDate").val());   
	var endDate   = $.trim($("#endDate").val());   
	var productId = $.trim($("#productId").val()); 
	var custNo    = $.trim($("#custNo").val()); 
	var transferType = $.trim($("#transferType").val()); 
	var postData = $custTransferList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
        'sp[beginDate]':beginDate,
        'sp[endDate]':endDate,
        'sp[transferType]':transferType,
        'sp[productId]':productId,
        'sp[custNo]':custNo
    });
    if (flag) {
    	$custTransferList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid", [{ page: 1 }]); //重新载入Grid表格
    } else {
    	$custTransferList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid"); //重新载入Grid表格
    }
}

